/*
 * $Id: Named.hpp 50 2009-02-10 05:48:05Z hyunghwan.chung $
 *
   Copyright 2005-2009 Chung, Hyung-Hwan.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an  BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

#ifndef _XP_NAMED_CLASS_
#define _XP_NAMED_CLASS_

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/bas/string.h>
#include <xp/bas/assert.h>

namespace xp 
{

	class Named 
	{
	public:

		Named (const xp_char_t* name = XP_T(""))
		{
			xp_assert (name != XP_NULL);
			// WARNING: a long name can be truncated
			xp_strxcpy (this->name_buf, XP_COUNTOF(this->name_buf), name);
		}
		virtual ~Named () {}

		xp_char_t* name ()
		{
			return this->name_buf;
		}

		const xp_char_t* name () const
		{
			return this->name_buf;
		}

		void setName (const xp_char_t* name)
		{
			xp_assert (name != XP_NULL);
			// WARNING: a long name can be truncated
			xp_strxcpy (this->name_buf, XP_COUNTOF(this->name_buf), name);
		}

		bool isNamed () const
		{
			return this->name_buf[0] != XP_T('\0');
		}

		bool isNamed (const xp_char_t* n) const
		{
			return xp_strcmp (this->name_buf, n) == 0;
		}

		enum 
		{
			MAX_NAME_LEN = 64
		};

	protected:
		xp_char_t name_buf[MAX_NAME_LEN + 1]; 
	};

}

#endif
